function DataGridColumnsCollapser() {
	this.dataGrid = null;
	this.colIndexes = null;
	this.container = null;
	this.tab = null;
	this.isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; 
}

DataGridColumnsCollapser.prototype.initialize = function(dataGrid, colIndexes, container) {
	this.dataGrid = dataGrid;
	this.colIndexes = colIndexes;
	this.container = container;
	// create tabs

	var dim = this.getColumnsArea(this.grid, this.colIndexes);
	var div = document.createElement("div");
	div.className = "collapseTab";
	div.style.left = dim.left + "px";
	div.style.width = dim.width + "px";
	var a = document.createElement("a");
	a.href = "javascript:void(0)";
	div.appendChild(a);
	var span = document.createElement("span");
	span.appendChild( document.createTextNode("Collapse") );
	a.appendChild( span );	
	$("collapseTabContainer").appendChild(div);
	Event.observe(a, "click", this.collapsableTab_onClick.bind(this));
	/*
	var o = new Object();
	o.colIndexes = colIndexes;
	o.tab = div;
	o.grid = grid;
	arrTabs.push(o);
	a.tabData = o;
	*/
}

DataGridColumnsCollapser.prototype.getColumnsArea = function(grid, colIndexes) {
	var left = 0;
	var width = 0;
	var headTds = grid.thead.firstChild.childNodes;
	for(var i=0; i<colIndexes.length; i++) {
		var ix = colIndexes[i];
		if(i==0) left = Position.cumulativeOffset(headTds[ix])[0];
		width += Element.getDimensions(headTds[ix]).width;
	}
	if(this.isIE) left++;
	return {left:left,width:width};
}


/*
 function createCollapsableTab(grid, colIndexes) {
	var dim = getColumnsDimensions(grid, colIndexes);
	var div = document.createElement("div");
	div.className = "collapseTab";
	div.style.left = dim.left + "px";
	div.style.width = dim.width + "px";
	var a = document.createElement("a");
	a.href = "javascript:void(0)";
	div.appendChild(a);
	var span = document.createElement("span");
	span.appendChild( document.createTextNode("Collapse") );
	a.appendChild( span );	
	$("collapseTabContainer").appendChild(div);
	Event.observe(a, "click", collapsableTab_onClick.bind(this));
	var o = new Object();
	o.colIndexes = colIndexes;
	o.tab = div;
	o.grid = grid;
	arrTabs.push(o);
	a.tabData = o;
}

function refreshTabs() {
	for(var i=0; i<arrTabs.length; i++) {
		var tabData = arrTabs[i];
		var dim = getColumnsDimensions(tabData.grid, tabData.colIndexes);
		tabData.tab.style.left = dim.left + "px";
		tabData.tab.style.width = dim.width + "px";
	}
}

function collapsableTab_onClick(e) {
	var a = Event.element(e);
	a.blur();
	var tabData = a.tabData;
	for(var i=0; i<mdGrid.subGrids.length; i++) {
		var subGrid = mdGrid.subGrids[i];
		subGrid.toogleColumns(tabData.colIndexes);
	}
	var tab = tabData.tab;
	var a = tab.getElementsByTagName("a")[0];
	if(Element.hasClassName(a, "collapsed")) {
		Element.removeClassName(a, "collapsed")
	} else {
		Element.addClassName(a, "collapsed")
	}
	refreshTabs();
}
 */